<template>
  <div class="questionnaire-container">
    <div class="questionnaire-content">
      <!-- 加载指示器 -->
      <div v-if="loading" class="loading-container">
        <i class="el-icon-loading"></i>
        <p>正在加载问卷数据，请稍候...</p>
      </div>

      <div v-else>
        <!-- 用户信息展示卡片 -->
        <div class="user-profile-card" v-if="userInfo.userId">
          <div class="user-profile-header">
            <div class="avatar-container">
              <div class="avatar-placeholder">
                {{
                  userInfo.userName
                    ? userInfo.userName.substr(0, 1).toUpperCase()
                    : "U"
                }}
              </div>
            </div>
            <div class="user-basic-info">
              <h3 class="user-name">{{ userInfo.userName }}</h3>
              <p class="user-role">
                {{
                  userInfo.roles && userInfo.roles.length > 0
                    ? userInfo.roles[0].roleName
                    : ""
                }}
              </p>
            </div>
          </div>
          <div class="user-profile-details">
            <div class="info-item">
              <div class="info-label"><i class="el-icon-user"></i> 昵称：</div>
              <div class="info-value">{{ userInfo.nickName }}</div>
            </div>
            <div class="info-item">
              <div class="info-label"><i class="el-icon-male"></i> 性别：</div>
              <div class="info-value">
                {{ userInfo.sex === "0" ? "男" : "女" }}
              </div>
            </div>
            <div class="info-item">
              <div class="info-label">
                <i class="el-icon-message"></i> 邮箱：
              </div>
              <div class="info-value">{{ userInfo.email || "暂无" }}</div>
            </div>
            <div class="info-item">
              <div class="info-label">
                <i class="el-icon-school"></i> 班级：
              </div>
              <div class="info-value">
                {{ userInfo.dept ? userInfo.dept.deptName : "暂无" }}
              </div>
            </div>

            <div
              class="info-item"
              v-if="
                taskDetail && taskDetail.length > 0 && taskDetail[0].commitTime
              "
            >
              <div class="info-label">
                <i class="el-icon-search"></i>提交时间：
              </div>
              <div class="info-value">
                {{ formatDateTime(taskDetail[0].commitTime) }}
              </div>
            </div>
          </div>
        </div>

        <!-- 任务详情卡片 -->
        <!-- <div class="task-detail-card" v-if="taskDetail && taskDetail.length > 0">
          <div class="task-detail-header">
            <i class="el-icon-s-order"></i>
            <h3>任务详情</h3>
          </div>
          <div class="task-detail-content">
            <div class="detail-item">
              <div class="detail-label">任务编号：</div>
              <div class="detail-value">{{ taskDetail[0].taskId || '暂无' }}</div>
            </div>
            <div class="detail-item">
              <div class="detail-label">量表编号：</div>
              <div class="detail-value">{{ taskDetail[0].scaleId || '暂无' }}</div>
            </div>
            <div class="detail-item">
              <div class="detail-label">创建人：</div>
              <div class="detail-value">{{ taskDetail[0].createBy || '暂无' }}</div>
            </div>
            <div class="detail-item">
              <div class="detail-label">创建时间：</div>
              <div class="detail-value">{{ formatDateTime(taskDetail[0].createTime) }}</div>
            </div>
            <div class="detail-item">
              <div class="detail-label">提交人：</div>
              <div class="detail-value">{{ taskDetail[0].commitUser || '暂无' }}</div>
            </div>
            <div class="detail-item">
              <div class="detail-label">提交时间：</div>
              <div class="detail-value">{{ formatDateTime(taskDetail[0].commitTime) }}</div>
            </div>
          </div>
        </div> -->

        <!-- 问卷内容 -->
        <div v-if="dataLoaded">
          <!-- <div class="questionnaire-header">
            <h2>{{ dynamicTitle }}</h2>
            <p v-if="isReadOnly && viewType === 'result'" class="view-only-notice">（测评结果查看模式）</p>
            <p v-else-if="isReadOnly" class="view-only-notice">（历史答卷查看模式）</p>
            <div class="progress-wrapper">
              <el-progress 
                :percentage="progressPercentage" 
                :format="progressFormat"
                :stroke-width="18"
                :status="isReadOnly ? 'info' : 'success'">
              </el-progress>
            </div>
          </div> -->

          <div class="section-info">
            <h3>{{ currentSection.title }}</h3>
            <p>{{ currentSection.description }}</p>
          </div>

          <div class="question-list">
            <div
              v-for="(question, qIndex) in currentSection.questions"
              :key="qIndex"
              class="question-section"
            >
              <div class="question-title">
                <span class="question-number">{{ qIndex + 1 }}.</span>
                <span class="question-text">{{ question.title }}</span>
                <span class="question-type" v-if="question.type === 'single'">[单选题]</span>
                <span class="question-type" v-else-if="question.type === 'multiple'">[多选题]</span>
                <span class="question-type" v-else-if="question.type === 'text'">[问答题]</span>
                <span class="question-type" v-else-if="question.type === 'rate'">[评分题]</span>
              </div>

              <div class="question-options">
                <el-radio-group
                  v-if="question.type === 'single'"
                  v-model="question.answer"
                  :disabled="isReadOnly"
                >
                  <el-radio
                    v-for="option in question.options"
                    :key="option.value"
                    :label="option.value"
                    class="option-item"
                  >
                    {{ option.label }}
                  </el-radio>
                </el-radio-group>

                <el-checkbox-group
                  v-else-if="question.type === 'multiple'"
                  v-model="question.answer"
                  :disabled="isReadOnly"
                >
                  <el-checkbox
                    v-for="option in question.options"
                    :key="option.value"
                    :label="option.value"
                    class="option-item"
                  >
                    {{ option.label }}
                  </el-checkbox>
                </el-checkbox-group>

                <div v-else-if="question.type === 'text'">
                  <el-input
                    type="textarea"
                    :rows="4"
                    placeholder="请输入您的回答"
                    v-model="question.answer"
                    maxlength="500"
                    show-word-limit
                    :disabled="isReadOnly"
                  ></el-input>
                </div>

                <div v-else-if="question.type === 'rate'">
                  <el-rate
                    v-model="question.answer"
                    :max="5"
                    :texts="[
                      '非常不满意',
                      '不满意',
                      '一般',
                      '满意',
                      '非常满意',
                    ]"
                    show-text
                    :disabled="isReadOnly"
                  ></el-rate>
                </div>
              </div>
            </div>
          </div>

          <div class="questionnaire-footer">
            <el-button
              @click="prevSection"
              :disabled="currentSectionIndex === 0"
              icon="el-icon-arrow-left"
            >
              上一页
            </el-button>
            <el-button
              v-if="currentSectionIndex < sections.length - 1"
              :type="isReadOnly ? 'info' : 'primary'"
              @click="nextSection"
              icon="el-icon-arrow-right"
            >
              下一页
            </el-button>
            <el-button
              v-else-if="showSubmitButton"
              type="success"
              @click="completeQuestionnaire"
              :disabled="!canProceed || isSubmitting"
              :loading="isSubmitting"
              icon="el-icon-check"
            >
              {{ isSubmitting ? '提交中...' : '完成' }}
            </el-button>
            <el-button
              v-else-if="
                isReadOnly && currentSectionIndex === sections.length - 1
              "
              type="info"
              @click="backToList"
              icon="el-icon-back"
            >
              返回列表
            </el-button>
          </div>
        </div>

        <div v-else class="no-data-message">
          <i class="el-icon-warning-outline"></i>
          <p>未找到问卷数据或数据加载失败</p>
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import {
  getTaskList,
  postTaskCommit,
  getListTaskId,
} from "@/api/system/assess";
import { getUserProfile } from "@/api/system/user";
export default {
  name: "Questionnaire",
  data() {
    return {
      id: "",
      taskDetail: [],
      userInfo: {},
      title: "心理测评问卷",
      currentSectionIndex: 0,
      loading: true,
      dataLoaded: false,
      sections: [],
      startTime: null, // 开始答题时间
      isSubmitting: false, // 防止重复提交标志
    };
  },
  computed: {
    currentSection() {
      return this.sections[this.currentSectionIndex];
    },
    dynamicTitle() {
      if (this.isReadOnly) {
        if (this.viewType === "result") {
          return `${this.title} - 测评结果`;
        } else {
          return `${this.title} - 历史答卷`;
        }
      }
      return this.title;
    },
    progressPercentage() {
      return Math.round(
        ((this.currentSectionIndex + 1) / this.sections.length) * 100
      );
    },
    // 判断是否是只读模式（回显历史答案）
    isReadOnly() {
      return (
        this.taskDetail &&
        this.taskDetail.length > 0 &&
        this.taskDetail[0] &&
        this.taskDetail[0].commitTime
      );
    },
    // 查看类型：result表示查看结果，question表示查看问卷
    viewType() {
      return this.$route.query.viewType || "question";
    },
    showSubmitButton() {
      // 如果是只回显历史答案模式，不显示完成按钮
      return !this.isReadOnly;
    },
    canProceed() {
      // Check if all questions in the current section are answered
      return this.currentSection.questions.every((question) => {
        if (question.type === "single" && question.answer) {
          return true;
        } else if (question.type === "multiple" && question.answer.length > 0) {
          return true;
        } else if (question.type === "text" && question.answer.trim()) {
          return true;
        } else if (question.type === "rate" && question.answer > 0) {
          return true;
        }
        return false;
      });
    },
  },
  created() {
    // 记录开始答题时间
    let startTimes = new Date();
    this.startTime = this.formatDateTime(startTimes);
    
    // 先获取当前用户信息
    this.getUser();

    // 解析URL参数
    const { taskId, scaleId, id, viewType, userId } = this.$route.query;

    // 检查必要参数
    if (!taskId && !id) {
      this.$message.error("缺少必要参数：任务ID");
      this.loading = false;
      return;
    }

    // 设置任务ID
    if (taskId) {
      this.id = taskId;
      // 先获取题目列表，再获取答案
      this.getTaskLists(scaleId)
        .then(() => {
          return this.getTaskListDetail();
        })
        .catch((error) => {
          console.error("获取任务数据失败:", error);
          this.loading = false;
          this.dataLoaded = false;
        });
    } else if (id) {
      this.getTaskLists(scaleId).catch((error) => {
        console.error("获取任务数据失败:", error);
        this.loading = false;
        this.dataLoaded = false;
      });
      this.id = id;
    }
  },
  methods: {
    getTaskListDetail() {
      // 创建参数对象
      const params = {
        taskId: this.$route.query.taskId,
      };

      // 如果指定了用户ID，添加到查询参数
      if (this.$route.query.userId) {
        params.commitUser = this.$route.query.userId;
      }

      return getListTaskId(params)
        .then((res) => {
          this.taskDetail = res.data;
          console.log("获取到任务详情数据:", this.taskDetail);

          // 处理提交的问卷回显，设置问题的答案
          this.processCommitQuestion();
          this.loading = false;
          this.dataLoaded = this.sections && this.sections.length > 0;
        })
        .catch((error) => {
          console.error("获取任务详情失败:", error);
          this.loading = false;
          this.dataLoaded = false;
        });
    },

    // 处理提交的答题内容
    processCommitQuestion() {
      if (!this.taskDetail || !this.taskDetail.length) {
        console.warn("没有任务详情数据，无法回显答案");
        return;
      }

      console.log("开始处理问卷回显数据");

      // 遍历所有返回的任务数据
      this.taskDetail.forEach((task, index) => {
        if (!task.commitQuestion) {
          console.warn(`任务 ${index + 1} 没有提交答案数据`);
          return;
        }

        try {
          // 解析commitQuestion字段
          let commitData;

          // 判断是否已经是JSON对象
          if (typeof task.commitQuestion === "object") {
            commitData = task.commitQuestion;
          } else {
            try {
              commitData = JSON.parse(task.commitQuestion);
            } catch (parseError) {
              console.error("JSON解析失败:", parseError, task.commitQuestion);
              return;
            }
          }

          console.log("解析后的提交数据:", commitData);

          // 找到对应的sectionId和questions数据
          if (
            commitData.sectionId &&
            commitData.questions &&
            Array.isArray(commitData.questions)
          ) {
            // 更新量表ID匹配逻辑，支持不同格式的ID比较
            const sectionId = Number(commitData.sectionId);
            console.log("查找量表ID:", sectionId);

            // 查找对应的section
            const sectionIndex = this.sections.findIndex((section) => {
              return (
                section.id === sectionId ||
                String(section.id) === String(sectionId)
              );
            });

            console.log("找到的量表索引:", sectionIndex);

            if (sectionIndex !== -1) {
              // 获取当前section和问题列表
              const currentSection = this.sections[sectionIndex];
              console.log("当前量表:", currentSection.title);
              console.log("问题数量:", currentSection.questions.length);

              // 遍历问题，设置答案
              commitData.questions.forEach((answerData) => {
                // 兼容不同ID格式
                const questionId = Number(answerData.questionId);

                // 找到问题索引
                const questionIndex = currentSection.questions.findIndex(
                  (q) => {
                    return (
                      q.id === questionId || String(q.id) === String(questionId)
                    );
                  }
                );

                if (questionIndex !== -1) {
                  // 获取问题
                  const question = currentSection.questions[questionIndex];

                  // 设置答案
                  question.answer = answerData.answer;

                  console.log(
                    `已回显: 问题 ${question.title}, 答案: ${answerData.answer}`
                  );
                } else {
                  console.warn(`未找到问题ID: ${questionId}`);
                }
              });
            } else {
              console.warn(`未找到量表ID: ${sectionId}`);
            }
          } else {
            console.warn("提交数据格式不符合预期:", commitData);
          }
        } catch (error) {
          console.error("解析提交的问卷数据失败:", error);
        }
      });
    },
    //用户信息
    getUser() {
      getUserProfile().then((res) => {
        console.log(res, "------------------------");
        this.userInfo = res.data;
      });
    },
    // 格式化日期时间显示
    formatDateTime(datetime) {
      if (!datetime) return "暂无";

      const date = new Date(datetime);
      const year = date.getFullYear();
      const month = String(date.getMonth() + 1).padStart(2, "0");
      const day = String(date.getDate()).padStart(2, "0");
      const hours = String(date.getHours()).padStart(2, "0");
      const minutes = String(date.getMinutes()).padStart(2, "0");
      const seconds = String(date.getSeconds()).padStart(2, "0");

      return `${year}-${month}-${day} ${hours}:${minutes}:${seconds}`;
    },
    getTaskLists(scaleId) {
      return new Promise((resolve, reject) => {
        this.loading = true;

        // 检查scaleId是否存在
        if (!scaleId) {
          this.loading = false;
          this.dataLoaded = false;
          this.$message.error("未指定量表ID，无法获取问卷数据");
          reject(new Error("未指定量表ID"));
          return;
        }

        getTaskList(scaleId)
          .then((res) => {
            if (!res.data || !res.data.length) {
              console.warn("未获取到问卷数据");
              this.loading = false;
              this.dataLoaded = false;
              this.$message.warning("未找到问卷数据或数据为空");
              reject(new Error("未获取到问卷数据"));
              return;
            }

            console.log("获取到量表数据:", res.data);

            // 设置问卷标题为第一个量表的名称
            this.title = res.data[0].name;

            // 转换问卷数据为页面可用格式
            this.sections = res.data.map((scale) => {
              // 解析问题
              let questions = [];
              try {
                const questionsData = JSON.parse(scale.questionIds);
                questions = questionsData.map((q, index) => {
                  const questionType =
                    q.type ||
                    (q.options && q.options.length > 0 ? "single" : "text");

                  // 过滤掉空选项并格式化
                  const filteredOptions = q.options
                    ? q.options.filter((opt) => opt && opt.name)
                    : [];
                  const formattedOptions = filteredOptions.map((opt) => ({
                    label: opt.name,
                    value: opt.name,
                    score: opt.score,
                  }));

                  return {
                    id: index + 1,
                    title: q.name,
                    type: questionType,
                    options: formattedOptions,
                    answer: questionType === "multiple" ? [] : "",
                  };
                });
              } catch (error) {
                console.error("解析问题数据出错:", error);
              }

              return {
                id: scale.id,
                title: scale.shortName || scale.name,
                description: scale.introduce || "",
                questions: questions,
              };
            });

            // 重置到第一部分
            this.currentSectionIndex = 0;
            this.dataLoaded = true;
            this.loading = false;

            // 解决Promise
            resolve(this.sections);
          })
          .catch((error) => {
            console.error("获取问卷数据失败:", error);
            this.loading = false;
            this.dataLoaded = false;
            reject(error);
          });
      });
    },
    progressFormat(percentage) {
      return `${this.currentSectionIndex + 1}/${this.sections.length}`;
    },
    nextSection() {
      if (
        this.canProceed &&
        this.currentSectionIndex < this.sections.length - 1
      ) {
        this.currentSectionIndex++;
        // Scroll to top when changing sections
        window.scrollTo(0, 0);
      } else if (!this.canProceed) {
        this.$message({
          message: "请完成本页所有问题后再继续",
          type: "warning",
        });
      }
    },
    prevSection() {
      if (this.currentSectionIndex > 0) {
        this.currentSectionIndex--;
        // Scroll to top when changing sections
        window.scrollTo(0, 0);
      }
    },
    completeQuestionnaire() {
      // 防止重复提交
      if (this.isSubmitting) {
        return;
      }
      
      // Check if all questions in all sections are answered
      const allAnswered = this.sections.every((section) =>
        section.questions.every((question) => {
          if (question.type === "single" && question.answer) {
            return true;
          } else if (
            question.type === "multiple" &&
            question.answer.length > 0
          ) {
            return true;
          } else if (question.type === "text" && question.answer.trim()) {
            return true;
          } else if (question.type === "rate" && question.answer > 0) {
            return true;
          }
          return false;
        })
      );

      if (!allAnswered) {
        this.$message({
          message: "请回答所有问题后再提交",
          type: "warning",
        });
        return;
      }

      // 设置提交状态
      this.isSubmitting = true;

      // 按要求的格式准备提交数据
      const commitQuestion = {};

      // 为每个量表处理数据
      this.sections.forEach((section) => {
        // 准备本量表的数据
        const sectionData = {
          sectionId: section.id,
          sectionTitle: section.title,
          questions: section.questions.map((q) => {
            let score = 0;

            if (q.type === "single") {
              const selectedOption = q.options.find(
                (opt) => opt.value === q.answer
              );
              score = selectedOption ? selectedOption.score : 0;
            } else if (q.type === "multiple") {
              q.answer.forEach((answer) => {
                const selectedOption = q.options.find(
                  (opt) => opt.value === answer
                );
                score += selectedOption ? selectedOption.score : 0;
              });
            } else if (q.type === "rate") {
              score = q.answer;
            }

            return {
              questionId: q.id,
              answer: q.answer,
              score: score,
            };
          }),
        };

        // 累计总分
        sectionData.totalScore = sectionData.questions.reduce(
          (sum, q) => sum + q.score,
          0
        );

        // 按照接口要求添加到commitQuestion对象中
        commitQuestion[section.id] = JSON.stringify(sectionData);
      });

      // 构建最终提交的数据
      const submitData = {
        taskId: this.id,
        commitQuestion: commitQuestion,
        startQuestionTime: this.startTime,
      };

      // 调用提交接口
      postTaskCommit(submitData)
        .then((res) => {
          if (res.code === 200) {
            this.$message({
              message: "问卷提交成功！",
              type: "success",
            });

            // 提交成功后跳转到完成页面
            this.$router.push({
              path: "/assessment/complete",
              query: {
                id: this.id,
                scaleId: this.scaleId,
                taskName:
                  this.taskDetail &&
                  this.taskDetail.length > 0 &&
                  this.taskDetail[0]
                    ? this.taskDetail[0].taskName
                    : "",
              },
            });
          } else {
            this.$message({
              message: res.msg || "提交失败，请重试",
              type: "error",
            });
          }
        })
        .catch((error) => {
          console.error("提交失败:", error);
          this.$message({
            message: "提交失败，请检查网络连接后重试",
            type: "error",
          });
        })
        .finally(() => {
          // 无论成功或失败都重置提交状态
          this.isSubmitting = false;
        });
    },
    backToList() {
      // 添加确认对话框
      this.$confirm("确定要返回列表页面吗?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "info",
      })
        .then(() => {
          // 返回首页
          this.$router.push("/");
        })
        .catch(() => {
          // 用户取消返回
          this.$message({
            type: "info",
            message: "已取消返回",
          });
        });
    },
  },
};
</script>

<style lang="scss" scoped>
.questionnaire-container {
  min-height: 100vh;
  background: #667eea;
  padding: 20px;
  position: relative;
  overflow-x: hidden;

  @media (max-width: 768px) {
    padding: 15px;
  }
}

.questionnaire-content {
  max-width: 900px;
  margin: 0 auto;
  background: rgba(255, 255, 255, 0.95);
  border-radius: 20px;
  padding: 30px;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.8);
  position: relative;
  z-index: 1;

  @media (max-width: 768px) {
    padding: 0;
    margin: 0;
    border-radius: 16px;
    width: 100%;
    box-sizing: border-box;
  }
}

.questionnaire-header {
  text-align: center;
  margin-bottom: 20px;

  h2 {
    margin-bottom: 20px;
    color: #303133;
  }

  .progress-wrapper {
    padding: 0 20px;
  }
}

.section-info {
  margin-bottom: 30px;
  padding: 25px 30px;
  background: #f6f9fc;
  border: none;
  border-radius: 16px;
  position: relative;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.08);

  &::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    width: 4px;
    height: 100%;
    background: #667eea;
    border-radius: 0 2px 2px 0;
  }

  h3 {
    margin-top: 0;
    margin-bottom: 12px;
    color: #2d3748;
    font-size: 20px;
    font-weight: 700;
    position: relative;
    z-index: 1;

    &::after {
      content: "";
      position: absolute;
      bottom: -4px;
      left: 0;
      width: 40px;
      height: 3px;
      background: #667eea;
      border-radius: 2px;
    }
  }

  p {
    margin-bottom: 0;
    color: #4a5568;
    line-height: 1.6;
    font-size: 15px;
    position: relative;
    z-index: 1;
  }
}

.question-list {
  margin-bottom: 20px;
}

.question-section {
  margin-bottom: 20px;
  padding: 20px 25px;
  background: #ffffff;
  border-radius: 12px;
  border: 1px solid rgba(102, 126, 234, 0.08);
  display: flex;
  flex-direction: column;
  position: relative;
  box-shadow: 0 2px 8px rgba(102, 126, 234, 0.06);

  &:last-child {
    margin-bottom: 0;
  }

  @media (max-width: 768px) {
    padding: 15px 18px;
  }
}

.question-title {
  font-size: 15px;
  font-weight: 500;
  color: #303133;
  display: flex;
  align-items: flex-start;
  margin-bottom: 15px;
  width: 100%;

  .question-number {
    font-weight: bold;
    margin-right: 8px;
    color: #409eff;
    min-width: 30px;
    flex-shrink: 0; // 题号不收缩
  }

  .question-text {
    flex: 1;
    word-wrap: break-word; // 允许换行
    word-break: break-word;
    line-height: 1.4;
  }

  .question-type {
    font-size: 12px;
    color: #909399;
    font-weight: normal;
    margin-left: 8px;
    background-color: #f0f5ff;
    padding: 2px 6px;
    border-radius: 3px;
    flex-shrink: 0;
    white-space: nowrap; // 题型标签不换行
  }

  @media (max-width: 768px) {
    margin-bottom: 12px;
    width: 100%;
  }
}

.question-options {
  width: 100%;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  flex-wrap: nowrap;
  overflow-x: auto;

  .option-item {
    display: inline-flex;
    align-items: center;
    margin-right: 15px;
    margin-bottom: 0;
    padding: 6px 12px;
    border-radius: 8px;
    white-space: nowrap;
    flex-shrink: 0;
    background: #f8fafc;
    border: 1px solid rgba(102, 126, 234, 0.08);
    position: relative;
    font-size: 13px;

    &:last-child {
      margin-right: 0;
    }

    @media (max-width: 768px) {
      margin-right: 10px;
      padding: 5px 10px;
      font-size: 12px;
    }
  }

  .el-radio,
  .el-checkbox {
    margin-right: 0;
    margin-bottom: 0;
    white-space: nowrap;
    position: relative;
    z-index: 1;
    font-size: 13px;

    .el-radio__label,
    .el-checkbox__label {
      font-size: 13px;
    }

    &.is-checked {
      .el-radio__label,
      .el-checkbox__label {
        color: #667eea;
        font-weight: 600;
      }
    }
  }

  // 文本域特殊处理
  .el-textarea {
    width: 100%;
    max-width: 400px;
    min-width: 200px;

    ::v-deep .el-textarea__inner {
      border-radius: 12px;
      border: 2px solid rgba(102, 126, 234, 0.1);
      background: #ffffff;
      resize: vertical;

      &:focus {
        border-color: #667eea;
        box-shadow: 0 0 0 4px rgba(102, 126, 234, 0.1);
        background: #ffffff;
      }
    }
  }

  .el-rate {
    margin-left: 10px;
    flex-shrink: 0;

    ::v-deep .el-rate__item {
      margin-right: 8px;

      .el-rate__icon {
        font-size: 20px;
      }
    }
  }

  @media (max-width: 768px) {
    justify-content: space-between;
    width: 100%;
    overflow: visible !important;
    flex-wrap: nowrap !important;
    min-width: 0;
    display: flex !important;
    align-items: center;

    .el-radio-group,
    .el-checkbox-group {
      display: flex !important;
      flex-wrap: wrap !important;
      width: 100%;
      justify-content: flex-start;
      align-items: center;
      gap: 2px;
    }

    .option-item {
      flex: 0 0 auto;
      white-space: nowrap !important;
      margin-right: 2px;
      margin-bottom: 0 !important;
      padding: 2px 4px;
      font-size: 9px !important;
      display: inline-flex !important;
      align-items: center;
      justify-content: center;
      line-height: 1.2;
      min-width: 0;
    }

    .el-radio,
    .el-checkbox {
      font-size: 7px !important;
      white-space: nowrap !important;
      display: inline-flex !important;
      align-items: center;
      justify-content: center;
      flex-shrink: 1 !important;
      margin-right: 0 !important;

      .el-radio__label,
      .el-checkbox__label {
        font-size: 9px !important;
        white-space: nowrap !important;
        line-height: 1.2;
        max-width: 100%;
        padding-left: 1px;
      }

      .el-radio__input,
      .el-checkbox__input {
        flex-shrink: 0 !important;
        margin-right: 1px;
      }
    }
  }
}

.questionnaire-footer {
  display: flex;
  justify-content: space-between;
  padding: 30px 0;
  margin-top: 30px;
  position: relative;

  &::before {
    content: "";
    position: absolute;
    top: 0;
    left: 50%;
    transform: translateX(-50%);
    width: 60%;
    height: 1px;
    background: linear-gradient(
      90deg,
      transparent 0%,
      rgba(102, 126, 234, 0.3) 20%,
      rgba(102, 126, 234, 0.6) 50%,
      rgba(102, 126, 234, 0.3) 80%,
      transparent 100%
    );
  }

  .el-button {
    min-width: 120px;
    height: 42px;
    border-radius: 21px;
    font-weight: 600;
    font-size: 14px;
    letter-spacing: 0.5px;
    position: relative;

    &.el-button--primary {
      background: #667eea;
      border: none;
    }

    &.el-button--success {
      background: #67c23a;
      border: none;
    }

    &.el-button--info {
      background: #909399;
      border: none;
    }

    &:disabled {
      opacity: 0.6;
    }
  }

  @media (max-width: 768px) {
    flex-direction: column;
    gap: 15px;
    padding: 25px 0;

    .el-button {
      width: 100%;
      max-width: 300px;
      margin: 0 auto;
    }
  }
}

.el-progress {
  margin-bottom: 15px;
}

// Mobile optimizations
@media (max-width: 480px) {
  .question-title {
    font-size: 15px;
  }

  .el-radio,
  .el-checkbox {
    font-size: 14px;
  }

  .section-info {
    h3 {
      font-size: 16px;
    }

    p {
      font-size: 14px;
    }
  }
}

/* 用户信息卡片样式 */
.user-profile-card {
  margin-bottom: 30px;
  border-radius: 16px;
  overflow: hidden;
  box-shadow: 0 8px 32px rgba(0, 0, 0, 0.12), 0 4px 16px rgba(0, 0, 0, 0.08);
  background: linear-gradient(135deg, #f8fafc 0%, #ffffff 100%);
  border: 1px solid rgba(255, 255, 255, 0.8);
  backdrop-filter: blur(10px);
  animation: cardFloat 0.6s ease-out;
  transition: all 0.3s cubic-bezier(0.25, 0.46, 0.45, 0.94);

  &:hover {
    transform: translateY(-2px);
    box-shadow: 0 12px 40px rgba(0, 0, 0, 0.15), 0 6px 20px rgba(0, 0, 0, 0.1);
  }
}

@keyframes cardFloat {
  from {
    opacity: 0;
    transform: translateY(20px) scale(0.95);
  }
  to {
    opacity: 1;
    transform: translateY(0) scale(1);
  }
}

.user-profile-header {
  padding: 25px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  display: flex;
  align-items: center;
  position: relative;

  &::before {
    content: "";
    position: absolute;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.1) 25%,
        transparent 25%,
        transparent 75%,
        rgba(255, 255, 255, 0.1) 75%
      ),
      linear-gradient(
        45deg,
        rgba(255, 255, 255, 0.1) 25%,
        transparent 25%,
        transparent 75%,
        rgba(255, 255, 255, 0.1) 75%
      );
    background-size: 20px 20px;
    background-position: 0 0, 10px 10px;
    opacity: 0.3;
  }
}

.avatar-container {
  margin-right: 25px;
  position: relative;
  z-index: 1;
}

.avatar-placeholder {
  width: 70px;
  height: 70px;
  border-radius: 50%;
  background: linear-gradient(135deg, #ffffff 0%, #f8fafc 100%);
  color: #667eea;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 28px;
  font-weight: bold;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.15),
    inset 0 1px 0 rgba(255, 255, 255, 0.8);
  border: 3px solid rgba(255, 255, 255, 0.9);
  transition: all 0.3s ease;

  &:hover {
    transform: scale(1.05);
    box-shadow: 0 12px 32px rgba(0, 0, 0, 0.2),
      inset 0 1px 0 rgba(255, 255, 255, 0.9);
  }
}

.user-basic-info {
  flex: 1;
  position: relative;
  z-index: 1;
}

.user-name {
  margin: 0 0 8px 0;
  font-size: 24px;
  font-weight: 600;
  text-shadow: 0 2px 4px rgba(0, 0, 0, 0.1);
  letter-spacing: 0.5px;
}

.user-role {
  margin: 0;
  opacity: 0.9;
  font-size: 15px;
  background: rgba(255, 255, 255, 0.2);
  padding: 4px 12px;
  border-radius: 12px;
  display: inline-block;
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255, 255, 255, 0.3);
}

.user-profile-details {
  padding: 30px;
  background: linear-gradient(180deg, #ffffff 0%, #fafbfc 100%);
  position: relative;

  &::before {
    content: "";
    position: absolute;
    top: 0;
    left: 30px;
    right: 30px;
    height: 1px;
    background: linear-gradient(
      90deg,
      transparent 0%,
      rgba(102, 126, 234, 0.3) 50%,
      transparent 100%
    );
  }
}

.info-item {
  display: flex;
  margin-bottom: 16px;
  padding: 12px 16px;
  border-radius: 10px;
  background: rgba(102, 126, 234, 0.02);
  border: 1px solid rgba(102, 126, 234, 0.05);
  transition: all 0.3s ease;

  &:hover {
    background: rgba(102, 126, 234, 0.05);
    border-color: rgba(102, 126, 234, 0.1);
    transform: translateX(2px);
  }

  &:last-child {
    margin-bottom: 0;
  }
}

.info-label {
  width: 130px;
  color: #4a5568;
  font-weight: 600;
  display: flex;
  align-items: center;
  font-size: 14px;
}

.info-label i {
  margin-right: 8px;
  font-size: 16px;
  color: #667eea;
  width: 20px;
  text-align: center;
}

.info-value {
  flex: 1;
  color: #2d3748;
  font-weight: 500;
  font-size: 14px;
}

.task-detail-card {
  background-color: #fff;
  border-radius: 8px;
  box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);
  padding: 20px;
  margin-bottom: 20px;

  .task-detail-header {
    display: flex;
    align-items: center;
    margin-bottom: 15px;
    border-bottom: 1px solid #f0f0f0;
    padding-bottom: 10px;

    i {
      font-size: 22px;
      color: #409eff;
      margin-right: 10px;
    }

    h3 {
      margin: 0;
      font-size: 18px;
      font-weight: 500;
      color: #333;
    }
  }

  .task-detail-content {
    .detail-item {
      display: flex;
      margin-bottom: 10px;

      .detail-label {
        width: 100px;
        color: #606266;
        font-weight: 500;
      }

      .detail-value {
        flex: 1;
        color: #303133;
      }
    }
  }
}

.loading-container {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 400px;
  text-align: center;
  position: relative;

  .el-icon-loading {
    font-size: 40px;
    color: #667eea;
    margin-bottom: 20px;
  }

  p {
    margin: 0;
    color: #4a5568;
    font-size: 16px;
    font-weight: 500;
  }
}

.no-data-message {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  min-height: 300px;
  text-align: center;
  background: #fef5e7;
  border-radius: 16px;
  padding: 40px;
  border: 1px solid rgba(230, 162, 60, 0.1);
  position: relative;

  i {
    font-size: 48px;
    color: #e6a23c;
    margin-bottom: 20px;
  }

  p {
    font-size: 18px;
    color: #8b4513;
    font-weight: 500;
    max-width: 300px;
    line-height: 1.5;
  }
}

.view-only-notice {
  color: #667eea;
  font-size: 14px;
  margin-top: -10px;
  margin-bottom: 15px;
  text-align: center;
  background: rgba(102, 126, 234, 0.1);
  padding: 8px 16px;
  border-radius: 12px;
  border: 1px solid rgba(102, 126, 234, 0.2);
  font-weight: 500;
}

/* Element UI 组件自定义样式 */
::v-deep .el-radio {
  .el-radio__input {
    .el-radio__inner {
      width: 18px;
      height: 18px;
      border: 2px solid #d1d5db;
    }

    &.is-checked {
      .el-radio__inner {
        background-color: #667eea;
        border-color: #667eea;

        &::after {
          width: 6px;
          height: 6px;
          background-color: #ffffff;
        }
      }
    }
  }

  .el-radio__label {
    font-size: 14px;
    color: #4a5568;
    font-weight: 500;
  }
}

::v-deep .el-checkbox {
  .el-checkbox__input {
    .el-checkbox__inner {
      width: 18px;
      height: 18px;
      border: 2px solid #d1d5db;
      border-radius: 4px;
    }

    &.is-checked {
      .el-checkbox__inner {
        background-color: #667eea;
        border-color: #667eea;

        &::after {
          border-color: #ffffff;
          border-width: 2px;
        }
      }
    }
  }

  .el-checkbox__label {
    font-size: 14px;
    color: #4a5568;
    font-weight: 500;
  }
}

::v-deep .el-rate {
  .el-rate__item {
    .el-rate__icon {
      color: #e4e7ed;
    }

    &.is-active {
      .el-rate__icon {
        color: #ff9800;
      }
    }
  }

  .el-rate__text {
    color: #667eea;
    font-weight: 600;
    font-size: 14px;
    margin-left: 8px;
  }
}

/* 进度条自定义样式 */
::v-deep .el-progress {
  .el-progress-bar {
    .el-progress-bar__outer {
      background-color: rgba(102, 126, 234, 0.1);
      border-radius: 12px;
      overflow: hidden;
    }

    .el-progress-bar__inner {
      background: #667eea;
      border-radius: 12px;
    }
  }

  .el-progress__text {
    color: #667eea !important;
    font-weight: 600 !important;
    font-size: 14px !important;
  }
}



/* 滚动条美化 */
::-webkit-scrollbar {
  width: 8px;
  height: 8px;
}

::-webkit-scrollbar-track {
  background: rgba(102, 126, 234, 0.05);
  border-radius: 4px;
}

::-webkit-scrollbar-thumb {
  background: #667eea;
  border-radius: 4px;
}

/* 选择高亮优化 */
::selection {
  background: rgba(102, 126, 234, 0.2);
  color: #2d3748;
}

::-moz-selection {
  background: rgba(102, 126, 234, 0.2);
  color: #2d3748;
}
</style>
